﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using celinda.Class;
using FluentNHibernate.Mapping;

namespace celinda.Map
{
    public class SocieteMap : ClassMap<Societe>
    {
        public SocieteMap()
        {
            Id(x => x.Id);
            Map(x => x.Nom);
            Map(x => x.Adresse);
            Map(x => x.CodePostal);
            Map(x => x.Ville);
            Map(x => x.Pays);
            Map(x => x.Siret);
            Map(x => x.RaisonSocial);
            Map(x => x.CapitalSocial);
            Map(x => x.DateCreation);
            Map(x => x.DateModification);
            Map(x => x.Etat);
            HasMany(x => x.Clients).KeyColumn("FkSocieteId").Cascade.All();
            HasMany(x => x.Sites).KeyColumn("FkSocieteId").Cascade.All();
            HasMany(x => x.Fournisseurs).KeyColumn("FkSocieteId").Cascade.All();
            HasMany(x => x.Utilisateurs).KeyColumn("FkSocieteId").Cascade.All();
            Table("Societes");
        }
    }

    public class UtilisateurMap : ClassMap<Utilisateur>
    {
        public UtilisateurMap()
        {
            Id(x => x.Id);
            Map(x => x.Login);
            Map(x => x.MotDePasse);
            Map(x => x.DateCreation);
            Map(x => x.DateModification);
            Map(x => x.Etat);
            References(x => x.Societe).Column("FkSocieteId").Nullable();
            Table("Utilisateurs");
        }
    }

    public class GenreMap : ClassMap<Genre>
        {
            public GenreMap()
            {
                Id(x => x.Id);
                Map(x => x.Libelle);
                Map(x => x.DateCreation);
                Map(x => x.DateModification);
                Map(x => x.Etat);
                Table("Genres");
            }
        }

    public class ClientMap : ClassMap<Client>
    {
        public ClientMap()
        {
            Id(x => x.Id);
            Map(x => x.Nom);
            Map(x => x.Prenom);
            Map(x => x.NumeroFidelite);
            Map(x => x.DateCreation);
            Map(x => x.DateModification);
            Map(x => x.Etat);
            References(x => x.Societe).Column("FkSocieteId");
            References(x => x.Genre).Column("FkGenreId");
            HasMany(x => x.Adresses).KeyColumn("FkClientId").Cascade.All();
            HasMany(x => x.Commandes).KeyColumn("FkClientId").Cascade.All();
            Table("Clients");
        }
    }

    public class AdresseTypeMap : ClassMap<AdresseType>
    {
        public AdresseTypeMap()
        {
            Id(x => x.Id);
            Map(x => x.Libelle);
            Map(x => x.DateCreation);
            Map(x => x.DateModification);
            Map(x => x.Etat);
            Table("AdresseTypes");
        }
    }

    public class AdresseMap : ClassMap<Adresse>
    {
        public AdresseMap()
        {
            Id(x => x.Id);
            Map(x => x.AdresseLib);
            Map(x => x.CodePostal);
            Map(x => x.Ville);
            Map(x => x.Pays);
            Map(x => x.Telephone);
            Map(x => x.Portable);
            Map(x => x.Fax);
            Map(x => x.Email);
            Map(x => x.DateCreation);
            Map(x => x.DateModification);
            Map(x => x.Etat);
            References(x => x.Client).Column("FkClientId");
            References(x => x.AdresseType).Column("FkAdresseTypeId");
            Table("Adresses");
        }
    }

    public class SiteMap : ClassMap<Site>
    {
        public SiteMap()
        {
            Id(x => x.Id);
            Map(x => x.Nom);
            Map(x => x.Adresse);
            Map(x => x.CodePostal);
            Map(x => x.Ville);
            Map(x => x.Pays);
            Map(x => x.DateCreation);
            Map(x => x.DateModification);
            Map(x => x.Etat);
            References(x => x.Societe).Column("FkSocieteId");
            Table("Sites");
        }
    }

    public class FournisseurMap : ClassMap<Fournisseur>
    {
        public FournisseurMap()
        {
            Id(x => x.Id);
            Map(x => x.Nom);
            Map(x => x.Adresse);
            Map(x => x.CodePostal);
            Map(x => x.Ville);
            Map(x => x.Pays);
            Map(x => x.DateCreation);
            Map(x => x.DateModification);
            Map(x => x.Etat);
            References(x => x.Societe).Column("FkSocieteId");
            HasMany(x => x.Commandes).KeyColumn("FkCommandeTeteId").Cascade.All();
            Table("Fournisseurs");
        }
    }

    public class ArticleMap : ClassMap<Article>
    {
        public ArticleMap()
        {
            Id(x => x.Id);
            Map(x => x.Libelle);
            Map(x => x.GendCod);
            Map(x => x.DateCreation);
            Map(x => x.DateModification);
            Map(x => x.Etat);
            References(x => x.Fournisseur).Column("FkFournisseurId");
            Table("Articles");
        }
    }

    public class CommandeFournisseurTeteMap : ClassMap<CommandeFournisseurTete>
    {
        public CommandeFournisseurTeteMap()
        {
            Id(x => x.Id);
            Map(x => x.DateMouvement);
            Map(x => x.DateCreation);
            Map(x => x.DateModification);
            Map(x => x.Etat);
            References(x => x.Fournisseur).Column("FkFournisseurId");
            HasMany(x => x.Lignes).KeyColumn("FkCommandeFournisseurTeteId").Cascade.All();
            Table("CommandeFournisseurTete");
        }
    }

    public class CommandeFournisseurLigneMap : ClassMap<CommandeFournisseurLigne>
    {
        public CommandeFournisseurLigneMap()
        {
            Id(x => x.Id);
            Map(x => x.Quantite);
            Map(x => x.Prix);
            Map(x => x.DateCreation);
            Map(x => x.DateModification);
            Map(x => x.Etat);
            References(x => x.Article).Column("FkArticleId");
            References(x => x.Commande).Column("FkCommandeFournisseurTeteId");
            Table("CommandeFournisseurLigne");
        }
    }

    public class CommandeClientTeteMap : ClassMap<CommandeClientTete>
    {
        public CommandeClientTeteMap()
        {
            Id(x => x.Id);
            Map(x => x.DateMouvement);
            Map(x => x.DateCreation);
            Map(x => x.DateModification);
            Map(x => x.Etat);
            References(x => x.AdresseFacturation).Column("FkAdresseFacturationtId");
            References(x => x.AdresseLivraison).Column("FkAdresseLivraisonId");
            References(x => x.Client).Column("FkClientId");
            HasMany(x => x.Lignes).KeyColumn("FkCommandeClientTeteId").Cascade.All();
            Table("CommandeClientTete");
        }
    }

    public class CommandeClientLigneMap : ClassMap<CommandeClientLigne>
    {
        public CommandeClientLigneMap()
        {
            Id(x => x.Id);
            Map(x => x.Quantite);
            Map(x => x.Prix);
            Map(x => x.DateCreation);
            Map(x => x.DateModification);
            Map(x => x.Etat);
            References(x => x.Article).Column("FkArticleId");
            References(x => x.Commande).Column("FkCommandeClientTeteId");
            Table("CommandeClientLigne");
        }
    }
}
